<!DOCTYPE html>
<html>
<head>
    <title>Hello world</title>
</head>
<body>
<script src="/static/js/jquery-1.11.3.js"></script>
<h2>欢迎来到Django</h2>
{% for i in List %}  {{ i }}   {% endfor %}
<div id="list"></div>
<h3>Django forms 示例</h3>
<form method='post'>
{% csrf_token %}
{{ form }}
<input type="button" value="计算" onclick=calc()>
</form>
<p>计算结果:<span id='res'></span></p>
</body>
<script type="text/javascript">
    var List = {{ JList|safe }};
    var ls = document.getElementById('list');
    for(i in List){
        ls.innerHTML += '<br>';
        ls.innerHTML += List[i];
    }
    function calc(){
        var a = document.getElementById('id_a').value;
        var b = document.getElementById('id_b').value;
        if (!a || a==0 || !b || b==0) return;
        
        $.get("/",{'a':a,'b':b}, function(ret){
            $('#res').html(ret)
        })
    }
</script>
</html>